package com.woniu.userservice.service.impl;

import com.woniu.userservice.entity.Collections;
import com.woniu.userservice.dao.CollectionsDao;
import com.woniu.userservice.service.CollectionsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("collectionsService")
public class CollectionsServiceImpl implements CollectionsService {
    @Resource
    private CollectionsDao collectionsDao;

    @Override
    public Collections queryById(Integer id) {
        return collectionsDao.queryById(id);
    }

    @Override
    public List<Collections> queryAllByLimit(int offset, int limit) {
        return collectionsDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<Collections> findAll() {
        return collectionsDao.findAll();
    }

    @Override
    public Collections insert(Collections collections) {
        collectionsDao.insert(collections);
        return collections;
    }

    @Override
    public Collections update(Collections collections) {
        collectionsDao.update(collections);
        return queryById(collections.getId());
    }

    @Override
    public boolean deleteById(Integer id) {
        return collectionsDao.deleteById(id) > 0;
    }

    /**
     * @param id     商品id
     * @param userid 用户id
     * @return 根据用户和商品Id取消收藏
     */
    @Override
    public boolean deleteByShopId(Integer id, Integer userid) {
        Boolean bo = collectionsDao.deleteByShopId(id, userid);
        if (bo) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param userId         用户id
     * @param goodsName      商品名字
     * @param collectionTime 时间
     * @param price          价格
     * @return 根据条件查询用户收藏
     */
    @Override
    public List<Collections> findByShop(Integer userId, String goodsName, Date collectionTime, Double price) {

        return collectionsDao.findByShop(userId, goodsName, collectionTime, price);
    }
}